package com.bitejiuyeke.forum.common;


import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class AppResult<T> {

    //状态码
    private int code;

    //
    private String message;

    private T data;

    public AppResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    //这里必须要求返回信息，所以没有提供空参构造
    public AppResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /*
    * 成功
    * */
    public static AppResult success(){
        return new AppResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage());
    }
    public static AppResult success(String message){
        return new AppResult(ResultCode.SUCCESS.getCode(), message);
    }
    public static <T> AppResult success(T data){
        return new AppResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }
    public static <T> AppResult success(T data, String message){
        return new AppResult(ResultCode.SUCCESS.getCode(), message, data);
    }
    /*
    * 失败
    * */
    public static AppResult failed()
    {
        return new AppResult(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage());
    }
    public static AppResult failed(String message)
    {
        return new AppResult(ResultCode.FAILED.getCode(), message);
    }
    //错误信息没有返回数据
  /*  public static <T> AppResult failed(T data)
    {
        return new AppResult(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage(), data);
    }*/

    public static AppResult failed(ResultCode resultCode)
    {
        return new AppResult(resultCode.getCode(), resultCode.getMessage());
    }

}
